package com.javandad.app.client.fodos;

import java.util.LinkedList;
import java.util.List;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.SimpleCheckBox;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.javandad.app.client.CodesvrParam;

public class FodosNode extends AbsolutePanel {

	public static List<FodosNode> fodosList = new LinkedList<FodosNode>();

	
	private void initGUI(final String url, final String id, FodosServiceAsync fsa) {
		
		this.setSize("200px", "200px");
		image.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				showBox.show();
			}
		});
		image.setSize("190px", "190px");
		image.setUrl(url);
		this.add(image, 5, 5);

	
		simpleCheckBox.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				
			}
		});
		add(simpleCheckBox, 5, 5);
	}

	public FodosNode(String url, String id, FodosServiceAsync fsa) {
		super();
		fodosList.add(this);
		this.id = id.trim();
		this.fsa = fsa;
		showBox = new ShowFodoDialogBox(url, this);
		initGUI(url,id, fsa);

	}
	
	
	void setAsProfileFodo(){
		fsa.setAsProfileFodo(id, new AsyncCallback<Boolean>() {

			@Override
			public void onFailure(Throwable caught) {
			}

			@Override
			public void onSuccess(Boolean result) {
				if (result){
					Window.open("fodos.jsp?"+CodesvrParam.getCodesvrParam(), "_self", "");

				}
			}
		});
	}
	

	public String getId() {
		return id;
	}

    SimpleCheckBox simpleCheckBox = new SimpleCheckBox();
	private Image image = new Image();
	private String id;
	private FodosServiceAsync fsa;
	private ShowFodoDialogBox showBox = null;
	
	
}
